// @ 516
// _(:з」∠)_
// 格式化时间
// format time

// 格式化当前时间/传入时间
function formatTime ( time, type, timex ) {
    var date = null;
    if ( time != '' ) {
        date = new Date( time );
    } else {
        date = new Date();
    }

    if ( timex != '' && timex != null ) date = new Date( new Date().getTime() + timex );
    if ( time != '' && timex != '' && timex != null ) date = new Date( new Date( time ).getTime() + timex );

    var seperator1 = "",
        seperator2 = "",
        seperator3 = "",
        seperator4 = "",
        month      = date.getMonth() + 1,
        strDate    = date.getDate(),
        strHour    = date.getHours(),
        strMinute  = date.getMinutes(),
        strSecond  = date.getSeconds(),
        currentdate = null;

    if (month >= 1 && month <= 9) month = "0" + month;
    if (strDate >= 0 && strDate <= 9) strDate = "0" + strDate;
    if (strHour >= 0 && strHour <= 9) strHour = "0" + strHour;

    if (type == "zh-cn") {
        seperator1 = "年";
        seperator2 = "月";
        seperator3 = "日";
        seperator4 = "时";
        currentdate = date.getFullYear() + seperator1 + month + seperator2 + strDate + seperator3 + " " + strHour + seperator4;
    } else if (type == "minusSign") {
        seperator1 = "-";
        seperator2 = ":";
        currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + strHour + seperator2 + strMinute + seperator2 + strSecond;
    } else if (type == "minusSign_x") {
        seperator1 = "-";
        seperator2 = "时";
        currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + strHour + seperator2;
    } else if (type == "day") {
        seperator1 = "-";
        currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    }  else if (type == "day_") {
        seperator1 = "";
        currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    } else if (type == "MonthDay") {
        seperator1 = "-";
        currentdate = month + seperator1 + strDate;
    } else if (type == "GMT") {
        seperator1 = "";
        currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + seperator1 + strHour + "0000";
    }

    return currentdate;
}

// 格式化距现在的已过时间
function formatPassTime ( startTime ) {
    var currentTime = Date.parse( new Date() ),
        time  = currentTime - startTime,
        day   = parseInt( time / ( 1000 * 60 * 60 * 24 ) ),
        hour  = parseInt( time / ( 1000 * 60 * 60 ) ),
        min   = parseInt( time / ( 1000 * 60 ) ),
        month = parseInt( day / 30 ),
        year  = parseInt( month / 12 );

    if ( year )  return year + "年前"
    if ( month ) return month + "个月前"
    if ( day )   return day + "天前"
    if ( hour )  return hour + "小时前"
    if ( min )   return min + "分钟前"
    else return '刚刚'
}

// 格式化距现在的剩余时间
function formatRemainTime ( endTime ) {
    var startDate = new Date(), // 开始时间
        endDate   = new Date(endTime), // 结束时间
        t = endDate.getTime() - startDate.getTime(), // 时间差
        d = 0, h = 0, m = 0, s = 0;

    if (t >= 0) {
        d = Math.floor( t / 1000 / 3600 / 24 );
        h = Math.floor( t / 1000 / 60 / 60 % 24 );
        m = Math.floor( t / 1000 / 60 % 60 );
        s = Math.floor( t / 1000 % 60 );
    }

    return d + "天 " + h + "小时 " + m + "分钟 " + s + "秒";
}